<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:rich="http://richfaces.org/rich"
	template="/layout/template.xhtml">

    <ui:define name="head">
      <link href="../stylesheet/useradmin.css" rel="stylesheet" type="text/css"/>
        
      <script type="text/javascript">
        function confirmDelete()
        {
          return confirm("Are you sure you wish to delete this user? This action cannot be undone.");
        }
      </script>
    </ui:define>  
   
    <ui:define name="body">

  	    <h1>User Manager</h1>  
  	    
        <s:button id="newUser" action="#{userAction.createUser}" styleClass="newuser" rendered="#{s:hasPermission('seam.user', 'create')}"/>
  	    
		<h:form>
        <rich:dataTable id="users" var="_user" value="#{users}" 
            styleClass="useradmin" headerClass="header" rowClasses="odd,even" columnClasses=",,enabled,action">
          <h:column>
            <f:facet name="header">Username</f:facet>
            #{_user}
          </h:column>
          <h:column>
            <f:facet name="header">Member of roles</f:facet>
            #{userSearch.getUserRoles(_user)}
          </h:column>
          <h:column>
            <f:facet name="header">Enabled</f:facet>
            <div class="#{identityManager.isUserEnabled(_user) ? 'check' : 'x'}"/>
          </h:column>
          <h:column>
            <f:facet name="header">Action</f:facet>
            <s:fragment rendered="#{s:hasPermission('seam.user', 'update')}">
              <h:commandLink id="edit" value="Edit" action="#{userAction.editUser(userSearch.selectedUser)}"/><span> | </span>
            </s:fragment>
            <s:fragment rendered="#{s:hasPermission('seam.user', 'update')}">
              <h:commandLink id="assignToCompany" value="Assign Company" action="#{companyAppointer.edit(userSearch.selectedUser)}"/><span> | </span>
            </s:fragment>
            <h:commandLink id="delete" value="Delete" action="#{identityManager.deleteUser(userSearch.selectedUser)}" 
                    rendered="#{s:hasPermission('seam.user', 'delete')}"
                    onclick="return confirmDelete()"/>
          </h:column>
  	    </rich:dataTable>
		</h:form>
	    
    </ui:define>
    
</ui:composition>
